package cn.wolfcode.restful.controller;

import cn.wolfcode.restful.domain.Department;
import cn.wolfcode.restful.service.IDepartmentService;
import cn.wolfcode.restful.util.JsonResult;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("departments")
public class DepartmentController {
    @Autowired
    private IDepartmentService departmentService;
    //查询全部
    @GetMapping
    public List<Department> queryAll(){

        return  departmentService.list();
    }
    //查询单个
    @GetMapping("{id}")
    public Department queryOne(@PathVariable Long id){
        return departmentService.getById(id);
    }
    //添加
    @PostMapping
    public JsonResult save(Department department){
        departmentService.save(department);
        return JsonResult.success(department);
    }
    //修改
    @PutMapping
    public JsonResult update(Department department){
        departmentService.updateById(department);
        return JsonResult.success(department);
    }
    //删除
    @DeleteMapping("{id}")
    public JsonResult delete(@PathVariable Long id ){
        departmentService.removeById(id);
        return JsonResult.success(id);
    }
}
